package com.study.user.web;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.Subject;
import org.apache.struts.chain.contexts.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.study.user.pojo.User;
import com.study.user.service.UserService;

@Controller
@RequestMapping("/user")
public class UserController  {
	@Autowired
	UserService userService;
	@RequestMapping("/guide")
	public String guide(){
		
		return "login";
	}
	
	@RequestMapping("/login")
	public String login(String username,String password){
		try{
			userService.doLogin(username,password);
			return "index";
		}catch(AuthenticationException e){
			e.printStackTrace();
			return "login";
		}
	}
	@RequestMapping("/regist")
	public String regist(String username,String password){
		boolean flag=userService.insertuser(username,password);
		if(flag){
			return "index";
		}else{
			return "register";
		}
	}


}
